using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;


namespace UselessExplorer
{
    public partial class frmTraces : Form
    {
        private static frmTraces instance;
        public static frmTraces Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new frmTraces();
                }
                return instance;
            }
        }

        public frmTraces()
        {
            InitializeComponent();
        }


        [DllImport("user32.dll")]
        static extern bool FlashWindow(IntPtr hwnd, bool bInvert);

        private void frmTraces_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
            this.Text = UselessExplorer.Properties.UselessResources.frmTracesTitle;
            this.ControlBox = true;

            //int gWidth = dgvLogs.Width - 5;
            //int msgWidth = (gWidth * 70) / 100;
            //int dateWidth = gWidth - msgWidth;

            //dgvLogs.Columns["Message"].Width = msgWidth;
            //dgvLogs.Columns["DateTime"].Width = dateWidth;

        }

        public void AddMessage(string category, string date, string method, string Message, string stackTrace)
        {
            if (Message != null)
            {
                if (!this.IsDisposed)
                {
                    FlashWindow(this.Handle, false);
                    string[] items = new string[5] { category, date, method, Message, stackTrace };
                    lvLogMessages.Items.Add(new ListViewItem(items));
                    

                    // Support for Error Logs Storage directly to SVN
                    // WebServLogs.ErrorLogs el = new UselessExplorer.WebServLogs.ErrorLogs();
                    // el.StoreErrorLogs(date + " : " + Message, "frmTraces");
                }
            }
        }


        private void lblFullErrorMsg_Click(object sender, EventArgs e)
        {

        }

        private void lvLogMessages_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lvLogMessages.SelectedIndices[0] > -1)
            {
                lblFullErrorMsg.Text = lvLogMessages.SelectedItems[0].SubItems[4].Text;
            }
        }

    }
}